package com.easy.web.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.easy.web.repository.BalanceRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @author linNaibin
 * @version V1.0
 * @Title: IndexController.java
 * @Package org.easy.web.controller
 * @Description: TODO
 * @date 2020年9月18日 上午10:40:02
 */
@Api(tags = "主页接口")
@Controller
@RequiredArgsConstructor
public class IndexController {

    private final BalanceRepository repository;

    @ApiOperation(value = "主页", notes = "主页")
    @GetMapping("/home")
    @ResponseBody
    public void home() {
        System.out.println(" home !!!");
    }

    @ApiOperation(value = "数组", notes = "数组")
    @ResponseBody
    @GetMapping("/array")
    public String array(@RequestBody Integer[] array) {
        System.out.println(" 数组:: " + Arrays.toString(array));
        return "success !!!";
    }


    @ApiOperation(value = "db", notes = "db")
    @ResponseBody
    @GetMapping("/db")
    public JSONArray queryDb() {
        JSONArray array = new JSONArray();
        repository.findAll().stream().forEach(array::add);
        return array;
    }


    @RequestMapping("/index")
    public String index() {

        System.out.println("index .. ... . ");

        return "index";

    }

}
